package com.interview.ujiuye3;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Copyright (C), 2018-2020
 * FileName: Demo2
 * Author:   kongfanyu
 * Date:     2020/10/13 14:29
 */
public class Demo2 {
    public static void main(String[] args) {
        User z3 = new User("张三",29);
        User l4 = new User("李四",30);

        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(z3);
        boolean b = atomicReference.compareAndSet(z3, l4);

        System.out.println("比较并交互:"+ b+"," + atomicReference.get() );

        b = atomicReference.compareAndSet(z3, l4);

        System.out.println("比较并交互:"+ b+"," + atomicReference.get() );
    }
}
